package com.kayang.webapi.service;

import com.kayang.common.db.Database;
import com.kayang.common.db.DatabaseFactory;
import com.kayang.nadapt.table.DataView;
import org.springframework.stereotype.Service;

/**
 * 接口得数据源管理
 * */
@Service
public class APIdataMannger {

    public  DataView getAPI(int funcId){
        String xsql = "select * from skyDataWebAPIs where id=@1 and  isnull(disabled, 0)=0 ";
        Database db = DatabaseFactory.getDatabase();
        DataView dv = db.query(xsql, funcId);
        return  dv;
    }

    public  DataView getImportTemplate(int funcId){
        String xsql = " select im.* from skyDataImports im where isnull(disabled, 0)=0 and id=(select tpid from skyDataWebAPIs api where api.id=@1) ";
        Database db = DatabaseFactory.getDatabase();
        DataView dv = db.query(xsql, funcId);
        return  dv;
    }


    public  DataView getIpList(int funcId, int uid){
        String sql = "select IP from skyDataWebAPIs_Permission where funcid=@1 and  urid=@2 ";
        Database db = DatabaseFactory.getMainDB();
        DataView dv = db.query(sql, funcId, uid);
        return dv;
    }

}
